using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace FadeJSON
{
    /// <summary>
    /// n
    /// </summary>
    public class JsonNumber : JsonBaseType
    {
        /// <summary>
        /// number
        /// </summary>
        private readonly double vNumber;

        /// <summary>
        /// n
        /// </summary>
        public override dynamic Value
        {
            get
            {
                return vNumber;
            }
        }

        #region ctor

        /// <summary>
        /// n
        /// </summary>
        /// <param name="value"></param>
        public JsonNumber(double value)
        {
            vNumber = value;
        }

        #endregion

        public override bool Equals(JsonBaseType other)
        {
            var right = other as JsonNumber;

            return (right != null) && (Math.Abs(this.vNumber - right.vNumber) < double.Epsilon);
        }

        public static implicit operator JsonNumber(int value)
        {
            return new JsonNumber(value);
        }

        public static implicit operator JsonNumber(double value)
        {
            return new JsonNumber(value);
        }

        public static implicit operator double(JsonNumber obj)
        {
            return obj.vNumber;
        }

        internal override void ToString(StringBuilder builder, ref int tab)
        {
            builder.Append(vNumber.ToString(CultureInfo.CurrentCulture));
        }

    }

}